<?php

namespace App\Admin\Forms;

use App\Models\Application;
use Dcat\Admin\Admin;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Http\JsonResponse;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;

class ZipPasswordForm extends Form implements LazyRenderable
{
    use LazyWidget;

    public function handle(array $input): JsonResponse
    {
        $app = Application::where('admin_id', Admin::user()->getKey())->first();

        $app->password = $input['password'];
        $app->save();

        return $this->response()->success('操作成功')->refresh();
    }

    public function form(): void
    {
        $this->text('password', '新密码')
            ->required();
    }
}
